package cn.janyd.action.utils;

import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import org.apache.commons.lang3.StringUtils;

/**
 * @author Janyd
 * @since 2020-08-08 17:38
 */
public class PsiFileUtils {

    public static VirtualFile findPackageDir(String packageName, String moduleRootPath) {
        packageName = "src/main/java/" + packageName;
        String path = FileUtil.toSystemIndependentName(moduleRootPath + "/" + StringUtils.replace(packageName, ".", "/"));
        return LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
    }

    public static VirtualFile findPath(String path) {
        return LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
    }
}
